package com.mygame.xinyue.handler;


import com.mygame.common.component.BaseRoute;
import com.mygame.common.component.RequestPacket;
import com.mygame.common.component.annotation.Handler;
import com.mygame.common.component.annotation.Route;
import com.mygame.common.msg.CommandEnum;
import com.mygame.common.msg.ServiceEnum;
import com.mygame.message.nats.NatsMessageContext;
import com.mygame.common.protobuf.ExternalMessage;
import com.mygame.common.protobuf.ExternalMessageUtil;
import com.mygame.common.protobuf.gameMsg.IMSendRequest;
import com.mygame.common.protobuf.gameMsg.IMSendResponse;
import org.springframework.stereotype.Component;

@Component
@Route(serviceType = ServiceEnum.GAME_LOGIC)
public class CommonHandler implements BaseRoute<RequestPacket> {

    @Override
    public void onReceive(RequestPacket packet) {
        System.out.println("CommonHandler");
    }

    @Handler(cmd = CommandEnum.C2S_SEND_IM_MSG)
    public void C2S_SEND_IM_MSG(IMSendRequest request, NatsMessageContext ctx) {
        String chat = request.getChat();
        IMSendResponse response = new IMSendResponse();
        response.setChat(chat);
        ExternalMessage message = ExternalMessageUtil.build(CommandEnum.S2C_SEND_IM_MSG, response);
        ctx.broadcastMessage(message);
    }
}